const HtmlWebpackPlugin = require('html-webpack-plugin')
const ModuleFederationPlugin = require('webpack/lib/container/ModuleFederationPlugin')

/** @type {import('webpack').Configuration} */
module.exports = {
    mode: 'development',
    entry: './src/main.js',
    plugins: [
        new HtmlWebpackPlugin({
            template: './public/index.html'
        }),

        new ModuleFederationPlugin({
            name: 'main',
            /**
             * 远程应用
             */
            remotes: {
                /**
                 * 字符串 “products” 和被导入模块的 name 属性值对应
                 * 属性 products 是映射别名，是在当前应用中导入该模块时使用的名字
                 */
                product: 'product@http://localhost:8082/remoteEntry.js',
                cart: 'cart@http://localhost:8081/remoteEntry.js'
            },
            //   shared: ['faker']
            shared: {
                faker: {
                    singleton: true
                }
            }
        })
    ]
}